package com.janj.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Test01 {
    //csr rsc
    public static void main(String[] args) throws Exception{
    //准备一些字符数据
     String url ="jdbc:mysql://192.168.65.47:3306/duod9" ;
     String username = "root";
     String password = "root";
     String sql ="SELECT * FROM phone";

     //获取到驱动
        Class.forName("com.mysql.jdbc.Driver");

     //获取到连接
       Connection conn = DriverManager.getConnection(url,username,password);

     // 获取到执行者
      Statement stat = conn.createStatement();

     //获取到结果集
        ResultSet resu = stat.executeQuery(sql);

     //遍历结果集
      while(resu.next()){
          int idValue = resu.getInt("id");
          String nameValue = resu.getString("name");
          int priceValue = resu.getInt("price");
          System.out.println(idValue+"\t"+nameValue+"\t"+priceValue);
      }

     //释放资源
      resu.close();
      stat.close();
      conn.close();

    }
}
